using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
using System.Threading;
namespace Sanchay
{
    public partial class DashBoard : Form
    {
        public DashBoard()
        {
            InitializeComponent();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            SparePurchaseRegister spr = new SparePurchaseRegister();
            spr.MdiParent = DashBoard.ActiveForm;
            spr.Show();
        }

      

        private void pictureBox6_Click(object sender, EventArgs e)
        {
          
            Stock objStock = new Stock();
            objStock.MdiParent = DashBoard.ActiveForm;
            objStock.Show();
          
        }

     
        private void pictureBox8_Click(object sender, EventArgs e)
        {
            AboutUs objAboutUs = new AboutUs();
            objAboutUs.ShowDialog();
        }

        private void pictureBoxSales_Click(object sender, EventArgs e)
        {

            SpareSalesRegister objSpareSalesRegister = new SpareSalesRegister();
            objSpareSalesRegister.MdiParent = DashBoard.ActiveForm;
            objSpareSalesRegister.Show();
        }


        //
        // Backup
        //
        private void pictureBox9_Click(object sender, EventArgs e)
        {

            FolderBrowserDialog oFolderBrowserDialog = new FolderBrowserDialog();
            oFolderBrowserDialog.ShowNewFolderButton = true;
          
            //Form2 frm = new Form2(this);
            //frm.ShowDialog();
           
            if ( oFolderBrowserDialog.ShowDialog()== DialogResult.OK)
            {
                string backupFolder = oFolderBrowserDialog.SelectedPath + "\\Sanchay_Backup_" + DateTime.Now.ToString("dd-MMM-yyyy");

                //string backupCommandText = "BACKUP DATABASE [db]" +
                //                            "TO  DISK = N'" + backupFolder + "' WITH NOFORMAT, NOINIT, " +
                //                            "NAME = N'db', SKIP, NOREWIND, NOUNLOAD,  STATS = 10";
                DataAccess da = new DataAccess();
                SqlConnection.ClearPool(da.conn);
                ProgressDialog oForm2 = new ProgressDialog(this);
                oForm2.ShowDialog();
               
              

                Directory.CreateDirectory(backupFolder);
                File.Copy("db.mdf", backupFolder + "\\db.mdf", true);
                File.Copy("db_log.ldf", backupFolder + "\\db_log.ldf", true);
            
            }
        }

        private void pictureBox10_Click(object sender, EventArgs e)
        {
           
        }

        private void pictureBox10_Click_1(object sender, EventArgs e)
        {
            Registers registers = new Registers();
            registers.MdiParent = DashBoard.ActiveForm;
            registers.Show();
            registers.ActivateStock(sender, e);
        }

        private void DashBoard_Load(object sender, EventArgs e)
        {

        }
    }
}